
package playground;

import cfar.ff.fun.F0;
import static cfar.ff.fun.Curry.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author badi
 */
public class Generator implements Runnable {
    String worker_inet_file;
    int sock;

    public Generator(String f, int s){
        worker_inet_file = f;
        sock = s;
    }

    public void run() {
        try {
            InetAddress worker = (InetAddress) Main.read(new FileInputStream(worker_inet_file));
            Socket server = new Socket(worker, sock);
            System.out.println("Connected to " + worker.getHostName());


            F0 f = curry(curry(new Add(), 40), 2);
            Main.write(f, server.getOutputStream());
            System.out.println("Sent work");

            System.out.println("Result " + Main.read(server.getInputStream()));

            
            server.close();
            
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Generator.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Generator.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
}
